package com.learning.spring.aop.base.proxy;

import com.learning.spring.aop.base.AopMonitor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * ClassName: ProxyHandler
 * Description: Spring AOP 原理：JDK 动态代理 aop 切入
 * Date: 2019/4/21 15:59 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class ProxyHandler implements InvocationHandler {

    /**
     * 被代理对象
     */
    private Object target;

    public ProxyHandler(Object target) {
        this.target = target;
    }

    /**
     * 监控的切入，在这边编码
     *
     * @param proxy
     * @param method
     * @param args
     * @return
     * @throws Throwable
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        AopMonitor.start();

        // 去操作新增的业务
        Object invoke = method.invoke(target, args);

        AopMonitor.end();


        return invoke;
    }
}
